/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('umeng-cmp', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CheckNotaryRequest {
  content?: string(name='content', description='A short description of struct'),
  txHash?: string(name='txHash'),
}

model CheckNotaryResponseBody = {
  code?: long(name='code'),
  data?: {
    blockHash?: string(name='blockHash'),
    blockHeight?: long(name='blockHeight'),
    reason?: string(name='reason'),
    result?: boolean(name='result'),
    saveTime?: string(name='saveTime'),
    txHash?: string(name='txHash'),
  }(name='data'),
  msg?: string(name='msg'),
  requestId?: string(name='requestId', description='Id of the request'),
}

model CheckNotaryResponse = {
  headers: map[string]string(name='headers'),
  body: CheckNotaryResponseBody(name='body'),
}

async function checkNotary(request: CheckNotaryRequest): CheckNotaryResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return checkNotaryWithOptions(request, headers, runtime);
}

async function checkNotaryWithOptions(request: CheckNotaryRequest, headers: map[string]string, runtime: Util.RuntimeOptions): CheckNotaryResponse {
  Util.validateModel(request);
  var query : map[string]any= {};
  if (!Util.isUnset(request.content)) {
    query['content'] = request.content;
  }
  if (!Util.isUnset(request.txHash)) {
    query['txHash'] = request.txHash;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CheckNotary',
    version = '2022-03-03',
    protocol = 'HTTPS',
    pathname = `/api/checkNotary`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model UploadNotaryRequest {
  content?: string(name='content', description='A short description of struct'),
}

model UploadNotaryResponseBody = {
  code?: long(name='code'),
  data?: string(name='data'),
  msg?: string(name='msg', description='Id of the request'),
  requestId?: string(name='requestId'),
}

model UploadNotaryResponse = {
  headers: map[string]string(name='headers'),
  body: UploadNotaryResponseBody(name='body'),
}

async function uploadNotary(request: UploadNotaryRequest): UploadNotaryResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return uploadNotaryWithOptions(request, headers, runtime);
}

async function uploadNotaryWithOptions(request: UploadNotaryRequest, headers: map[string]string, runtime: Util.RuntimeOptions): UploadNotaryResponse {
  Util.validateModel(request);
  var query : map[string]any= {};
  if (!Util.isUnset(request.content)) {
    query['content'] = request.content;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'UploadNotary',
    version = '2022-03-03',
    protocol = 'HTTPS',
    pathname = `/api/uploadNotary`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

